package com.siysoft.tc.admin.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.siysoft.tc.admin.service.IAdminSchoolService;
import com.siysoft.tc.base.bean.to.Interest;
import com.siysoft.tc.base.bean.to.School;
import com.siysoft.util.IMap;
import com.tc.base.dao.BaseDAO;

/**
 * 方法摘要：实现后台管理员管理功能接口 作者：zhouyu 日期：2015年6月5日
 * 
 * @param iMap
 * @return
 * @throws Exception
 */

@Service
public class AdminSchoolServiceImpl implements IAdminSchoolService {
	@Autowired
	BaseDAO baseDao;

	@Override
	public List<Map<String, Object>> seekSchools(IMap iMap) throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from db_school ";
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public Map<String, String> toSchoolRevise(IMap iMap) throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from db_school "
				+ "where school_id = "
				+ iMap.getInt("school_id")
				+ " ";
		// 将查询结果存到list下
		List list = baseDao.findBySQLToMap(hql, iMap, -1, -1);
		// 判断list中是否存在数据
		if (list.size() > 0) {
			// list中存在数据返回list第一条数据
			return (Map<String, String>) list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public void reviseSchoolInfo(IMap iMap) {
		// TODO Auto-generated method stub
		School school = (School)baseDao.findById(School.class, iMap.getInt("school_id"));
		System.out.println((String) iMap.get("school_name"));
		System.out.println( iMap.getInt("school_id"));
		String school_name = (String) iMap.get("school_name");
		school.setSchool_name(school_name);
		baseDao.update(school);
	}

	@Override
	public Integer addSchools(IMap iMap) {
		// TODO Auto-generated method stub
		School school = new School();
		school.setSchool_name(iMap.getString("name"));
		Integer id = (Integer) baseDao.saveReturnId(school);
		return id;
	}

	@Override
	public void delSchool(IMap iMap) {
		School school = (School)baseDao.findById(School.class, iMap.getInt("id"));
		baseDao.delete(school);
	}

	
}
